<cfcomponent name="cfesapi.org.owasp.esapi.Logger">

    <cfset MAX_VALUE = createObject('java','java.lang.Integer').MAX_VALUE />
    <cfset MIN_VALUE = createObject('java','java.lang.Integer').MIN_VALUE  />
    <cfset variables.levels = StructNew() />
		<cfset variables.levels.ALL     = MIN_VALUE />
		<cfset variables.levels.TRACE   = 100 />
		<cfset variables.levels.DEBUG   = 200 />
		<cfset variables.levels.INFO    = 400 />
		<cfset variables.levels.WARN    = 600 />
		<cfset variables.levels.ERROR   = 800 />
		<cfset variables.levels.FATAL   = 1000 />
		<cfset variables.levels.OFF     = MAX_VALUE />
		<cfset variables.levelVal       = "" />
    <cfset logger = '' />

  <cffunction name="init" access="public" returntype="Logger" output="false">
	  <cfargument name="javaLoggerInstance" type="any" required="false" default="">
	  <cfif arguments.javaLoggerInstance is ''>
	    <cfset loader = createObject('component' , 'ClassLoader').init() />
	    <cfset logger = loader.create('org.owasp.esapi.ESAPI').log() />
	   <cfelse>
	     <cfset logger = arguments.javaLoggerInstance />
	   </cfif>
		<cfreturn this />
 </cffunction>


<cfscript>
 function getJLogger() {
    return logger;
  }


function info(message){
 logger.info(logger.EVENT_FAILURE, message);
}

</cfscript>



	<cffunction name="getLevel" access="public" returntype="string" output="false">
		<cfreturn lcase(variables.level) />
	</cffunction>

	<cffunction name="setLevel" access="public" returntype="void" output="false">
		<cfargument name="level" type="String" required="false" default="info" />

		<cftry>
			<cfset variables.levelVal = StructFind(variables.levels, arguments.level) />
			<cfset variables.level = arguments.level />
			<cfcatch>
				<cfset createObject("component", "cfesapi.org.owasp.esapi.errors.LoggerException").init("Invalid Log Level") />
			</cfcatch>
		</cftry>
	</cffunction>
</cfcomponent>





<!--- <cfcomponent displayname="Logger" output="false">

  <cffunction name="init" access="public" returntype="Any" output="false">
		<cfargument name="name" type="string" required="true" hint="Logger Name" />
    <cfargument name="ESAPI" type="WEB-INF.cftags.component" required="true" hint="Pass in the ESAPI Service Locator" />
		<cfargument name="level" type="string" required="false" default="WARN" hint="The log level of this logger" />



    <!---
	public static final int OFF = Integer.MAX_VALUE;
	public static final int FATAL = 1000;
  public static final int ERROR = 800;
  public static final int WARNING = 600;
  public static final int INFO = 400;
  public static final int DEBUG = 200;
  public static final int TRACE = 100;
  public static final int ALL = Integer.MIN_VALUE;
     --->

		<cfset variables.ESAPI = arguments.ESAPI />
		<cfset variables.name = arguments.name />

    <cfset MAX_VALUE = createObject('java','java.lang.Integer').MAX_VALUE />
    <cfset MIN_VALUE = createObject('java','java.lang.Integer').MIN_VALUE  />
<!--- I wonder if these should be properties easily set? --->
		<cfset variables.levels = StructNew() />
		<cfset variables.levels.ALL     = MIN_VALUE />
		<cfset variables.levels.TRACE   = 100 />
		<cfset variables.levels.DEBUG   = 200 />
		<cfset variables.levels.INFO    = 400 />
		<cfset variables.levels.WARN    = 600 />
		<cfset variables.levels.ERROR   = 800 />
		<cfset variables.levels.FATAL   = 1000 />
		<cfset variables.levels.OFF     = MAX_VALUE />
		<cfset variables.levelVal       = "" />

		<cfset setLevel(arguments.level) />

		<cfreturn this />
	</cffunction>

	<cffunction name="getLevel" access="public" returntype="string" output="false">
		<cfreturn lcase(variables.level) />
	</cffunction>

	<cffunction name="setLevel" access="public" returntype="void" output="false">
		<cfargument name="level" type="String" required="false" default="info" />

		<cftry>
			<cfset variables.levelVal = StructFind(variables.levels, arguments.level) />
			<cfset variables.level = arguments.level />
			<cfcatch>
				<cfset createObject("component", "cfesapi.org.owasp.esapi.errors.LoggerException").init("Invalid Log Level") />
			</cfcatch>
		</cftry>
	</cffunction>

	<cffunction name="getLevelVal" access="private" returntype="numeric" output="false">
		<cfreturn variables.levelVal />
	</cffunction>

	<cffunction name="trace" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isTraceEnabled()>
			<cfset logEntry("TRACE", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="debug" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isDebugEnabled()>
			<cfset logEntry("DEBUG", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="info" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isInfoEnabled()>
			<cfset logEntry("INFO", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="warn" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isEnabledFor("warn")>
			<cfset logEntry("WARN", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="error" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isEnabledFor("error")>
			<cfset logEntry("ERROR", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="fatal" access="public" returntype="void" output="false">
		<cfargument name="message" type="string" required="true" hint="The message to log">

		<cfif isEnabledFor("fatal")>
			<cfset logEntry("FATAL", arguments.message) />
		</cfif>
	</cffunction>

	<cffunction name="isTraceEnabled" access="public" returntype="boolean" output="false">
		<cfif getLevelVal() LTE variables.levels.trace>
			<cfreturn true />
		<cfelse>
			<cfreturn false />
		</cfif>
	</cffunction>

	<cffunction name="isDebugEnabled" access="public" returntype="boolean" output="false">
		<cfif getLevelVal() LTE variables.levels.debug>
			<cfreturn true />
		<cfelse>
			<cfreturn false />
		</cfif>
	</cffunction>

	<cffunction name="isInfoEnabled" access="public" returntype="boolean" output="false">
		<cfif getLevelVal() LTE variables.levels.info>
			<cfreturn true />
		<cfelse>
			<cfreturn false />
		</cfif>
	</cffunction>

	<cffunction name="isEnabledFor" access="public" returntype="boolean" output="false">
		<cfargument name="level" type="String" required="true" hint="" />

		<cftry>
			<cfif getLevelVal() LTE StructFind(variables.levels, arguments.level)>
				<cfreturn true />
			<cfelse>
				<cfreturn false />
			</cfif>

			<cfcatch><cfreturn false /></cfcatch>
		</cftry>
	</cffunction>

	<cffunction name="logEntry" access="public" returntype="void" output="false">
		<cfargument name="type" type="String" required="true" hint="The log type that was used (i.e. INFO, DEBUG)">
		<cfargument name="message" type="string" required="false" default="No Message Passed" />

		<!--- local vars --->
		<cfset var logMessage = "" />
		<cfset var clean = "" />

		<!--- Get the sessions unique logging ID (We don't use the sessionID because it can be used for session hijaking) --->
		<cfset var userSessionLoggingID = variables.ESAPI.sessionFacade().getSessionProperty("loggingID") />

		<!--- Get the current User --->
		<cfset var user = variables.ESAPI.authenticator().getCurrentUser() />

		<!--- Set a local variable to hold ColdFusions non-standard log levels --->
		<cfset var cfType = "" />

		<!--- Determine which non-standard CF Log Level to use --->
		<cfswitch expression="#arguments.type#">
			<cfcase value="fatal"><cfset cfType = "fatal"></cfcase>
			<cfcase value="error"><cfset cfType = "error"></cfcase>
			<cfcase value="warn"><cfset cfType = "warning"></cfcase>
			<cfdefaultcase><cfset cfType="information"></cfdefaultcase>
		</cfswitch>

		<!--- Clean CRLF from the message --->
		<cfset logMessage = replace(arguments.message,"\n", "_", "all") />
		<cfset logMessage = replace(logMessage, "\r", "_", "all") />

		<!--- If HTMLEncoding Log entries is required --->
		<cfif variables.ESAPI.securityConfiguration().getProperty("LogEncodingRequired")>
			<cfset clean = variables.ESAPI.encoder().encodeForHTML(logMessage) />
			<cfif Compare(logMessage, clean)>
				<cfset logMessage = clean & " (Encoded)" />
			</cfif>
		</cfif>

		<!--- Make log entry --->
		<cflog type="#cfType#"
			application="true"
			file="SECURITY-#variables.name#"
			text="Level: #arguments.type# - Logger Name: #variables.name# - Username: #user.getUsername()# - Host: #user.getLastHostAddress()# - Session Logging ID: #userSessionLoggingID# - Message: #logMessage#" />

	</cffunction>
</cfcomponent> --->